﻿using System;

namespace b5
{
    public interface Shape
    {
        public  abstract double getArea();
    }
    class Triangle:Shape
    {
        public  double getArea()
        {
            //s==1/4sqrt[(a+b+c)(a+b-c)(a+c-b)(b+c-a)]
            return 0.25 * Math.Sqrt((a + b + c) * (a + b - c) * (a + c - b) * (b + c - a));
        }
        public Triangle()
        {
            
        }
        public Triangle(double a, double b, double c)
        {
            this.a = a;
            this.b = b;
            this.c = c;
        }
        public void setA(double a)
        {
            this.a = a;
        }
        public void setB(double b)
        {
            this.b = b;
        }
        public void setC(double c)
        {
            this.c = c;
        }
        public double getA()
        {
            return this.a;
        }
        public double getB()
        {
            return this.b;
        }
        public double getC()
        {
            return this.c;
        }
        private double a;
        private double b;
        private double c;
    }
    class Rectangle : Shape
    {
        public  double getArea()
        {//s==l*w
            return l * w;
        }
        public Rectangle()
        {

        }
        public Rectangle(double l, double w)
        {
            this.l = l;
            this.w = w;
        }
        public void setL(double l)
        {
            this.l = l;
        }
        public void setW(double w)
        {
            this.w = w;
        }
        public double getL()
        {
            return this.l;
        }
        public double getW()
        {
            return this.w;
        }
        private double l;
        private double w;
    }

    class Square : Shape
    {
        public  double getArea()
        {//s==l*w
            return d * d;
        }
        public Square()
        {

        }
        public Square(double d)
        {
            this.d = d;
        }
        public void setD(double d)
        {
            this.d = d;
        }
        public double getD()
        {
            return this.d;
        }
        private double d;
    }
    class Factory
    {
        public static Shape GetShape(string request)
        {
            Shape s = null;
            if (request == "T")
            {
                double ta, tb, tc;
                Console.WriteLine("请输入第1条边的长度：");
                string ta_s = Console.ReadLine();
                Console.WriteLine("请输入第2条边的长度：");
                string tb_s = Console.ReadLine();
                Console.WriteLine("请输入第3条边的长度：");
                string tc_s = Console.ReadLine();
                ta = Convert.ToDouble(ta_s);
                tb = Convert.ToDouble(tb_s);
                tc = Convert.ToDouble(tc_s);
                return new Triangle(ta,tb,tc);
            }else if(request=="R"){
                Console.WriteLine("请输入长：");
                string l_s = Console.ReadLine();
                Console.WriteLine("请输入宽：");
                string w_s = Console.ReadLine();
                double l = Convert.ToDouble(l_s);
                double w = Convert.ToDouble(w_s);
                return new Rectangle(l,w);
            }else if (request == "S")
            {
                Console.WriteLine("请输入边长：");
                string d_s = Console.ReadLine();
                double d = Convert.ToDouble(d_s);
                return new Square(d);
            }
            else
            {
                return s;
            }
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            Shape[] product = new Shape[10];
            
            while (i < 10)
            {
                Console.WriteLine("请输入需要的形状：T:三角形 R：长方形 S：正方形");
                string re = Console.ReadLine();
                if (re != "T" & re != "R" & re != "S")
                {
                    Console.WriteLine("输入错误");
                }
                else
                {
                    product[i] = Factory.GetShape(re);
                    i++;
                }
                
            }
            double totalArea=0;
            for(int j = 0; j < 10; j++)
            {
                totalArea += product[j].getArea();
            }
            Console.WriteLine("总面积：" + totalArea);

        }
    }
}
